﻿using System;
using System.Web.Mvc;
using IFDB.Models.Tables;
using IFDB.ResourceLibrary;
using IFDB.ViewModels.PageViewModels;
using IFDB.ViewModels.PartialViewModels;

namespace IFDB.MVC.Controllers
{
    public class LeagueController : Controller
    {
        public ActionResult Index(Guid? competitionId = null, Guid? seasonId = null, DateTime? startDate = null, DateTime? endDate = null)
        {
            LeagueViewModel leagueViewModel = new LeagueViewModel(Country.England, competitionId, seasonId ,startDate, endDate, 1);
            return View(leagueViewModel);
        }

        public ActionResult _LeagueTable(LeagueViewModel leagueViewModel)
        {
            return PartialView(leagueViewModel);
        }

        public ActionResult _MatchList(Guid? competitionId = null, Guid? seasonId = null, DateTime? startDate = null, DateTime? endDate = null, int? page = 1)
        {
            LeagueViewModel leagueViewModel = new LeagueViewModel(Country.England, competitionId, seasonId, startDate, endDate, (int)page);
            return PartialView("~/Views/Shared/Match/_CompetitionMatchList.cshtml", leagueViewModel.CompetitionMatchListViewModel);
        }

        public ActionResult _FixtureList(Guid? competitionId = null, Guid? seasonId = null, DateTime? startDate = null, DateTime? endDate = null, int? page = 1)
        {
            LeagueViewModel leagueViewModel = new LeagueViewModel(Country.England, competitionId, seasonId, startDate, endDate, (int)page);
            return PartialView("~/Views/Shared/Match/_CompetitionFixtureList.cshtml", leagueViewModel.CompetitionFixtureListViewModel);
        }

        public ActionResult _GetSeasonDates(string idString)
        {
            SeasonViewModel seasonViewModel = new SeasonViewModel();

            Season season = seasonViewModel.GetSeason(idString);
            string startDate = season.StartDate.ToString("yyyy-MM-dd");
            string endDate = DateTime.Now >= season.EndDate ? season.EndDate.ToString("yyyy-MM-d") : DateTime.Now.ToString("yyyy-MM-d");

            return Json(new { startDate = startDate, endDate = endDate }, JsonRequestBehavior.AllowGet);
        }
    }
}
